<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <meta charset="UTF-8">
    <title>已办事项</title>
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="../../css/global.css" media="all"/>
    <style>
        .layui-disabled {
            color: #0C0C0C !important;
        }
    </style>
</head>
<body style="overflow: auto">
<div class="panel-page">
    <div class="top-box">
        <span id="dtTitle"></span>
    </div>
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <form class="layui-form form-container" lay-filter="scoreRuleForm" style="width: 1100px;margin: 0 auto"
              action="">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">巡察单位</label>
                    <div class="layui-input-inline">
                        <select name="branch" lay-filter="branch" class="layui-disabled" id="branch" lay-search
                                lay-verify="required">
                            <option value=""></option>
                        </select>
                    </div>

                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">审核人</label>
                    <div class="layui-input-inline">
                        <select name="reviewer" class="layui-disabled" id="reviewer" lay-verify="required"
                                lay-filter="reviewer">
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">

                <div class="layui-inline">
                    <label class="layui-form-label">巡察年度</label>
                    <div class="layui-input-inline">
                        <select name="year" id="year" lay-verify="required" lay-filter="xmFilter" class="xg">
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">问题类别</label>
                    <div class="layui-input-inline">
                        <select name="questionType" class="layui-disabled" id="questionType" lay-verify="required"
                                lay-filter="questionType">
                            <option value=""></option>
                        </select>
                    </div>
                </div>

            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">问题来源</label>
                    <div class="layui-input-inline">
                        <select name="sourceProblem" class="layui-disabled" id="sourceProblem" lay-verify="required"
                                lay-filter="sourceProblem">
                            <option value=""></option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">问题项</label>
                <div class="layui-input-block" style="margin-left: 150px;width: 740px">
                    <textarea placeholder="请输入问题项" readonly maxlength="100" id="question" name="question"
                              class="layui-textarea layui-disabled" style="height: 100px"></textarea>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">问题描述</label>
                <div class="layui-input-block" style="margin-left: 150px;width: 740px">
                    <textarea placeholder="请输入问题描述" name="questionDetail" readonly id="questionDetail"
                              class="layui-textarea layui-disabled" style="height: 150px"></textarea>
                </div>
            </div>

            <!--反馈-->
            <div class="layui-form-item fk">
                <div class="layui-inline">
                    <label class="layui-form-label">进度</label>
                    <div class="layui-input-inline">
                        <select name="schedule" id="schedule" lay-verify="required" lay-filter="xmFilter">
                            <option value=""></option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline fk">
                    <label class="layui-form-label">反馈日期</label>
                    <div class="layui-input-inline">
                        <input type="text" name="feedBackDate" id="date" lay-verify="date" placeholder="yyyy-MM-dd"
                               autocomplete="off" class="layui-input">
                    </div>
                </div>
            </div>

            <!--反馈-->
            <div class="layui-form-item fk">
                <div class="layui-form-item">
                    <label class="layui-form-label">整改落实情况</label>
                    <div class="layui-input-block" style="margin-left: 150px;width: 740px">
                        <textarea placeholder="请输入内容" name="remark" class="layui-textarea"></textarea>
                    </div>
                </div>
            </div>

            <div class="layui-form-item fk">
                <div class="layui-input-block">
                    <button class="layui-btn save2" lay-submit lay-filter="feedBackBtn" id="btn6">提交</button>
                    <button type="button" class="layui-btn" id="btn2">上传附件</button>
                    <!--                    <button type="button" class="layui-btn" id="btn3">查看附件</button>-->
                </div>
            </div>
        </form>

        <div class="outer-page-inner">
            <div class="title-container zgjd">
                整改进度
                <i class="layui-icon layui-icon-up"></i>
            </div>
            <div class="widget-body no-padding zgjd">
                <table id="progress" class="table table-striped table-bordered table-hover" style="width:100%">
                    <thead>
                    <tr>
                        <th style="display: none">id</th>
                        <th>整改进度</th>
                        <th>整改时间</th>
                        <th>整改落实情况</th>
                        <th>联络员</th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript" src="../../js/libs/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript">

    //获取url后的参数值
    function getUrlParam(key) {
        var href = window.location.href;
        var url = href.split("?");
        if (url.length <= 1) {
            return "";
        }
        var params = url[1].split("&");

        for (var i = 0; i < params.length; i++) {
            var param = params[i].split("=");
            if (key == param[0]) {
                return param[1];
            }
        }
    }

    // 上传附件
    layui.use(['upload', 'form'], function () {
        var upload = layui.upload
            , form = layui.form;

        //执行实例
        var uploadInst = upload.render({
            elem: '#btn2' //绑定元素
            , url: '/mOverseeQuestions/uploadSource' //上传接口
            , accept: 'file'
            , multiple: true
            , method: 'POST',
            data: {
                branch: $("#branch option:selected").text()
            },
            done: function (res) {
                //上传完毕回调
                layer.msg('上传成功');
                var path = $("#btn2").val();
                if ( path != null && path != ''){
                    $("#btn2").val(path +','+ res.msg);
                }else {
                    $("#btn2").val(res.msg)
                }

            }
            , error: function (res) {
                //请求异常回调
                layer.msg("上传失败！");
            }
        });
    });

    //刷新表单
    function renderForm() {
        layui.use('form', function () {
            var form = layui.form; //高版本建议把括号去掉，有的低版本，需要加()
            form.render();
        });
    }

    /*初始化下拉*/
    function setOption() {
        document.getElementById("dtTitle").innerText = "督察问题记录-反馈";

        // 例如：new Option(item.xm, item.id)第一个参数是下拉列表中显示的值  第二个参数是选中传递给后台的值
        layui.use(['form', 'upload', 'layer', 'laydate'], function () {
                var year, questionKeyword, questionType, branch, schedule, sourceProblem, reviewer;
                var form = layui.form
                    , laydate = layui.laydate;

                //日期
                laydate.render({
                    elem: '#date'
                    , trigger: 'click'
                });

                $("#branch").attr("disabled", "disabled");
                $("#reviewer").attr("disabled", "disabled");
                $("#year").attr("disabled", "disabled");
                $("#questionType").attr("disabled", "disabled");
                $("#sourceProblem").attr("disabled", "disabled");
                renderForm();

                /*单位*/
                branch = $.ajax({
                    url: '/dropDown/getBranch',
                    dataType: 'json',
                    type: 'post',
                    async: false,
                    success: function (data) {
                        // 使用循环遍历，给下拉列表赋值
                        $.each(data, function (index, value) {
                            $('#branch').append(new Option(value.value, value.key));// 下拉菜单里添加元素
                        });
                        renderForm();//重新渲染 固定写法
                    }
                })
                    /*巡查年度*/
                    , year = $.ajax({
                    url: '/dropDown/getYear',
                    dataType: 'json',
                    type: 'post',
                    success: function (data) {
                        // 使用循环遍历，给下拉列表赋值
                        $.each(data, function (index, value) {
                            $('#year').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                        });
                        form.render();//重新渲染 固定写法
                    }
                })
                    /*类别*/
                    , questionType = $.ajax({
                    url: '/dropDown/getQuestion',
                    dataType: 'json',
                    type: 'post',
                    async: false,
                    success: function (data) {
                        // 使用循环遍历，给下拉列表赋值
                        $.each(data, function (index, value) {
                            $('#questionType').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                        });
                        renderForm();//重新渲染 固定写法
                    }
                })
                    /*关键字*/
                    , questionKeyword = $.ajax({
                    url: '/dropDown/getQuestionKeyword',
                    dataType: 'json',
                    type: 'post',
                    async: false,
                    success: function (data) {
                        // 使用循环遍历，给下拉列表赋值
                        $.each(data, function (index, value) {
                            $('#questionKeyword').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                        });
                        renderForm();//重新渲染 固定写法
                    }
                })
                    /*问题来源*/
                    , sourceProblem = $.ajax({
                    url: '/dropDown/getSourceProblem',
                    dataType: 'json',
                    type: 'post',
                    async: false,
                    success: function (data) {
                        // 使用循环遍历，给下拉列表赋值
                        $.each(data, function (index, value) {
                            $('#sourceProblem').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                        });
                        renderForm();//重新渲染 固定写法
                    }
                })
                    /*审核人*/
                    , reviewer = $.ajax({
                    url: '/dropDown/getReviewer',
                    dataType: 'json',
                    type: 'post',
                    async: false,
                    success: function (data) {
                        if (data.length == 0) {
                            layer.msg("该公司没有审核人员！", {
                                icon: 2,
                                time: 1000
                            })
                        }
                        $("#reviewer").empty();
                        // 使用循环遍历，给下拉列表赋值
                        $.each(data, function (index, value) {
                            $('#reviewer').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                        });
                        renderForm();//重新渲染 固定写法
                        console.log("审核人");
                    }
                })
                    /*进度*/
                    , schedule = $.ajax({
                    url: '/dropDown/getSchedule',
                    dataType: 'json',
                    type: 'post',
                    async: false,
                    success: function (data) {
                        // 使用循环遍历，给下拉列表赋值
                        $.each(data, function (index, value) {
                            $('#schedule').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                        });
                        renderForm();//重新渲染 固定写法
                    }
                });
                $.when(branch, year, questionType, questionKeyword, sourceProblem, reviewer, schedule).done(function () {
                    setFormValue()
                });
            }
        );
    }

    function setFormValue() {
        // 数据回显
        layui.use(['layer', 'form'], function () {
            var id = getUrlParam("id");
            if (id > 0) {
                $.ajax({
                    type: 'get',
                    url: '/mOverseeQuestions/' + id,
                    async: false,
                    success: function (data) {
                        console.log(data)
                        $("#question").val(data.question);
                        $("#questionId").val(data.questionId);
                        $("#questionDetail").val(data.questionDetail);
                        $("#remark").val(data.remark);
                        $("#startPatrolTime").val(data.startPatrolTime);
                        $("#liaison").val(data.liaison);
                        /*下拉*/
                        $("#branch").val(data.branchId);
                        $("#year").val(data.startPatrolTime);
                        $("#questionType").val(data.questionType);
                        $("#questionKeyword").val(data.questionKeyword);
                        $("#sourceProblem").val(data.sourceProblem);
                        $("#reviewer").val(data.reviewer);
                        renderForm();
                    }
                });
            }
        });
    }

    // 区域展开伸缩
    $('.title-container .layui-icon').click(function () {
        var thisIcon = $(this);
        if (thisIcon.hasClass("layui-icon-up")) {
            thisIcon.removeClass("layui-icon-up").addClass("layui-icon-down");
            thisIcon.parent().next().slideUp(200)
        } else {
            thisIcon.removeClass("layui-icon-down").addClass("layui-icon-up");
            thisIcon.parent().next().slideDown(200)
        }
    })

    function PanelInit() {
        init()
        setOption()
        /*整改进度*/
        progressInit()
    }

    var progress;

    function progressInit() {
        progress = $('#progress').DataTable({
            "searching": false,
            "processing": false,
            "serverSide": true,
            'iDisplayLength': 5,
            "ordering": false,
            "language": {
                "url": "/js/plugin/datatables/Chinese.lang"
            },
            "ajax": {
                "url": "/questionRecords/list",
                "type": "get",
                "data": function (d) {
                    d.overseeQuestionId = getUrlParam("id");
                    d.type = 2;
                },
            },
            "dom": "<'dt-toolbar'r>t<'dt-toolbar-footer table-page-footer'<'table-bottom col-sm-10 col-xs-12 hidden-xs'i><'table-bottom col-xs-12 col-sm-10' p v>>",
            "columns": [
                {"data": "questionStatus", "defaultContent": ""},
                {
                    "data": "feedBackDate", "defaultContent": "",
                    render: function (data, type, row, meta) {
                        return dateFormat(data, "yyyy-MM-dd");
                    }
                },
                {"data": "detail", "defaultContent": ""},
                {"data": "updateUser", "defaultContent": ""},
            ],
            "order": [[0, "asc"]]
        });
    }

    //监听提交
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;


        //监听反馈提交
        form.on('submit(feedBackBtn)', function (data) {
            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.save2').addClass(DISABLED);
            // 增加属性
            $('.save2').attr('disabled', 'disabled');
            data.field.id = getUrlParam("id");
            data.field.branchId = $("#branch option:selected").val();//获取文本 id: 以降序排列此列
            data.field.branch = $("#branch option:selected").text();//获取文本 id: 以降序排列此列
            data.field.questionKeyword = $("#questionKeyword option:selected").text();//获取文本
            data.field.questionType = $("#questionType option:selected").text();//获取文本
            data.field.questionStatus = $("#schedule option:selected").text();//获取文本
            data.field.sourceProblem = $("#sourceProblem option:selected").text();//获取文本
            console.log($("#btn2").val())
            data.field.file = $("#btn2").val();
            data.field.auditOpinion = null;
            $.ajax({
                type: 'POST',
                dataType: 'json',
                url: '/mOverseeQuestions/feedBack',
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(data.field),
                success: function (res) {
                    console.log(res);
                    if (res.errorCode == 0) {
                        layer.msg("反馈成功", {
                            icon: 1,
                            time: 1000
                        }, function () {
                            window.close();
                        });
                    }

                }
            })
            return false;
        });
    });

    function init() {
        var id = getUrlParam("id");
        $.ajax({
            type: 'POST',
            dataType: 'text',
            url: '/mOverseeQuestions/getYiBan/' + id,
            success: function (data) {

                if ("3" === data) {
                    document.getElementById("dtTitle").innerText = "督察问题记录";
                    $('.xg').attr('disabled', 'disabled');
                    $('.fk').css('display', 'none');
                    $('.sh').css('display', 'none');

                    document.getElementById("schedule").removeAttribute("lay-verify");
                    document.getElementById("date").removeAttribute("lay-verify");
                    document.getElementById("btn2").style.display = "none";
                    document.getElementById("btn6").style.display = "none";
                }
                /*督办反馈*/
                else if ("2" === data) {
                    document.getElementById("dtTitle").innerText = "督察问题记录-反馈";
                    $('.xg').attr('disabled', 'disabled');
                    $('.sh').css('display', 'none');
                    $('.shjl').css('display', 'none');


                } else {
                    document.getElementById("dtTitle").innerText = "督察问题记录";
                    $('.xg').attr('disabled', 'disabled');
                    $('.sh').css('display', 'none');
                    $('.fk').css('display', 'none');
                    document.getElementById("btn2").style.display = "none";
                    document.getElementById("btn6").style.display = "none";
                }
            }
        })
    }


    function dateFormat(dateString, format) {
        if (!dateString) return "";
        var time = new Date(dateString.replace(/-/g, '/').replace(/T|Z/g, ' ').trim());
        var o = {
            "M+": time.getMonth() + 1, //月份
            "d+": time.getDate(), //日
            "h+": time.getHours(), //小时
            "m+": time.getMinutes(), //分
            "s+": time.getSeconds(), //秒
            "q+": Math.floor((time.getMonth() + 3) / 3), //季度
            "S": time.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(format)) format = format.replace(RegExp.$1, (time.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(format)) format = format.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return format;
    }

    PanelInit()

</script>
</body>
</html>



